home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c,comp.lang.c++,comp.os.ms-windows.programmer.misc,comp.os.msdos.programmer,comp.programming,comp.windows.ms.programmer
- Path: txnews.amd.com!news
- From: Clark Archer <carcher@f25mail.amd.com>
- Subject: Re: Date Arithmetic
- Content-Type: text/plain; charset=us-ascii
- Message-ID: <3124A458.7BF8@f25mail.amd.com>
- Sender: news@txnews.amd.com
- Nntp-Posting-Host: graywolf
- Content-Transfer-Encoding: 7bit
- Organization: Advanced Micro Devices, Inc.
- References: <4g19kp$640@tracy.protocom.com>
- Mime-Version: 1.0
- Date: Fri, 16 Feb 1996 15:35:52 GMT
- X-Mailer: Mozilla 2.0b6a (WinNT; I)
-
- Michael J. Karas wrote:
- >
- > I am working on an algorithm for a laser marking machine that writes
- > expiration delays on to food product boxes. The algorithm needs to
- > be able to add NNN days to todays date in the fastest manner possible
- > without using any floating point arithmetic. I could use help from anyone
- > that has C code for doing this. It would be nice if the solution took the
- > leap year problem in to account including the special case of the year
- > 2000. Thanks in advance to anyone who could share their knowledge on this
- > subject.
- > -----
- > Michael Karas | EMail: mkaras@pclink.com
- > Carousel Design Solutions | America OnLine: MJKaras
- > 6021 Logan Avenue South | Voice: (612) 861-1284
- > Minneapolis MN 55419 | Fax: (612) 861-1386
- > -----
-
- You could use the C runtime library function time() to get the current
- time and then add NNN * SECS_PER_DAY to it and then convert back to a
- struct tm like:
-
- #define SECS_PER_DAY 86400
-
- time_t tmtNow;
- struct tm tmThen;
-
- tmtNow = time(NULL);
- tmtNow += (nDaysToAdd * SECS_PER_DAY);
- tmThen = *localtime(tmtNow);
-
-
- Then you can examine the contents of the tmThen struct to get
- month/day/year info.
-
- NOTE: This may not account correctly for daylight savings time.
-
- Clark
-